#define _CRT_SECURE_NO_WARNINGS 1
#include"queue.h"

void queueInit(qu* p)
{
	assert(p);
	p->head = NULL;
	p->tail = NULL;
}
void queueprintf(qu* p)
{
	assert(p);
	sl* s = p->head;
	while (s != NULL)
	{
		printf("%2d", s->data);
		s = s->next;
	}
}
void queuedestory(qu* p)
{
	assert(p);
	sl* s = p->head;
	while (s != NULL)
	{
		qu* next = s->next;
		free(s);
		s = next;
	}
	p->head = p->tail = NULL;
}
void queuepush(qu* p, dataty x)
{
	assert(p);
	sl* new = (sl*)malloc(sizeof(sl));
	new->data = x;
	new->next = NULL;
	if (p->head==NULL)
	{
		p->head = p->tail = new;
	}
	else
	{
		p->tail->next = new;
		p->tail = new;
	}
	sl* s = p->tail;

}
void queuepop(qu* p)
{
	assert(p);
	assert(!queuempty(p));
	//assert(p->head == NULL);
	sl* s = p->head->next;
	free(p->head);
	p->head = s;
	if (p->head == NULL)
	{
		p->tail = NULL;
	}
}
dataty queuefront(qu* p)
{
	return p->head->data;
}
dataty queueback(qu* p)
{
	return p->tail->data;
}
int queuesize(qu* p)
{
	int n = 0;
	sl* s = p->head;
	while (s)
	{
		n++;
		s = s->next;
	}
	return n;
}
bool queuempty(qu* p) 
{
	return p->head == NULL;
}
